
/* $Id */

using System;
using System.IO;

class PacketWriter
{
	private MemoryStream m_Stream;
	private int m_Length;

	public PacketWriter(int capacity)
	{
		m_Stream = new MemoryStream(capacity);
		m_Length = 0;
	} //
	
	public void Write(byte value)
	{
		m_Stream.WriteByte(value);
		m_Length++;
	} //
	
	public void Write(bool value)
	{
		m_Stream.WriteByte(Convert.ToByte(value));
		m_Length++;
	} //

	public void Write(string value)
	{
		var data = System.Text.Encoding.ASCII.GetBytes(value);
		m_Stream.Write(data, 0, data.Length);
		m_Length += data.Length;
	} //

	public void Write(UInt32 value)
	{
		m_Stream.Write(BitConverter.GetBytes(value), 0, 4);
		m_Length += 4;
	} //
	
	public byte[] GetData()
	{
		byte[] data = new byte[m_Length];
		Buffer.BlockCopy(m_Stream.GetBuffer(), 0, data, 0, m_Length);
		return data;
	} //
	
} // class

